package com.advertisementsystem.Mapper;

import com.advertisementsystem.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;

import java.util.List;


@Mapper
public interface UserMapper extends BaseMapper<User> {
    /**
     * 根据角色ID查询用户ID列表
     */
    @Select("SELECT u.id FROM user u " +
            "JOIN user_role ur ON u.id = ur.user_id " +
            "WHERE ur.role_id = #{roleId}")
    List<Long> selectUserIdsByRoleId(@Param("roleId") Long roleId);


    @Select("SELECT * FROM user WHERE username = #{name}")
    User selectByUsernameDirect(@Param("name") String username);

    @Select("SELECT * FROM user WHERE id = #{userId}")
    User getUserById(Long userId);
}
